package main

import (
	"fmt"
	"net/http"
	"net/url"
)

func getWithParams() {
	//创建请求
	request, err := http.NewRequest(http.MethodGet, "http://httpbin.org/get", nil)
	if err != nil {
		fmt.Printf("创建请求失败，err-->%v", err)
		return
	}

	//创建参数对象
	params := make(url.Values)
	params.Add("name", "hedaodao")
	params.Add("note", "你好，世界")

	//将参数对象，添加到请求体上
	request.URL.RawQuery = params.Encode() //Encode是对参数进行URL编码

	//设置请求头
	request.Header.Add("user-agent", "chrome")

	//发起请求
	response, err := http.DefaultClient.Do(request)
	if err != nil {
		fmt.Printf("发起请求失败，err-->%v", err)
		return
	}

	//读取响应体的body
	res := readBody(response)
	fmt.Println(string(res))
}
